/*
 **********************************************************
 *
 * Program 	 :	heap.c
 *
 * Write by  :	IBRAHIMLI NIHAT
 *
 * Summary 	 :  Contains data structures of the heap, 
 * 					error code and function prototype on the heap
 *
 * Date 	 :	Avril 27, 2013
 *
 ***********************************************************
 */

#include <stdio.h>
#include <stdlib.h>

#ifndef HEAP_H_
#define HEAP_H_

#define HEAP_NULL 200
#define HEAP_NON_NULL 201
#define HEAP_OVERFLOW 202
#define HEAP_EMPTY 204
#define HEAP_INDEX_ERROR 205
#define HEAP_VERTEX_NOT_FOUND 207

// TypHeap data structure
typedef struct TypHeap {	
	// the vertex
	int vertex;
	// the weight of edge
	double weight;
	// the predecessor vertex
	int predecessorVertex;
} TypHeap;

// Heap data structure
typedef struct Heap
{	
	// an array of type TypHeap
	TypHeap* array;
	// the number of items
	int nbMember;
	// the size of the heap
	int size;
}Heap;

// To initialize the heap
int initHeap(Heap**, int);

/*Insert an element of type TypHeap into the heap */
int insertElem(Heap*, TypHeap);

// give index of left child 
int leftChild(int);

// give index of right child 
int rightChild(int);

// give index of parent
int parent(int);

//replace the values of index1 and index2
void swap(Heap*, int, int);

// sort the heap
int heapSort(Heap*, int);

// build the heap
int buildHeap(Heap*);

//extract an element of type TypHeap which its value of weight is min
int extractMin(Heap*, TypHeap*);

// check out the member of the heap
int memberOfHeap(Heap, int);

// get the weight of the vertex 
double getWeightOfVertex(Heap, int);

// set the predecessor of vertex
int setPredecessorVertex(Heap*, int, int);

// set the weight of the vertex 
int setWeightOfVertex(Heap*, int, double);

// print the heap
void printHeap(Heap);

// free the heap
int freeHeap(Heap* heap);

#endif /* HEAP_H_ */